// pages/patient/patient.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    patients: [],
    num: 0,
    isReport:'',
  },
  // 点击添加就诊人
  put: function () {
    var num = this.data.num
    if (num >= 6) {
      wx.showToast({
        title: '最多添加6个人',
        icon: 'none',
        duration: 2000
      })
      return false
    } else {
      wx.navigateTo({
        url: '../addingvisitors/addingvisitors'
      })
    }
  },
  /**
   * 编辑就诊人信息
   */
  editPatient(e) {
    var familyID = e.currentTarget.dataset.familyid
    console.log(familyID)
    if(this.data.isReport){
      wx: wx.navigateBack({     //返回上一个页面
      })
    }else{
      wx.navigateTo({
        url: '../addingvisitors/addingvisitors?familyID=' + familyID,
      })
    }
  },

  delete: function (e) {
    var that = this
    var familyID = e.currentTarget.dataset.familyid
    console.log(familyID)
    wx.showModal({
      title: '提示',
      content: '你确认移除本就诊人？',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          that.binddeleted(familyID)
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    return false
  },

  binddeleted: function (familyID) {

    wx.request({
      url: getApp().globalData.myHttp + '/family/delete?FamilyID=' + familyID,
      method: "POST",
      success: (result) => {
        if (result.data.success) {
          this.setData({ patients: [] })
          this.getPatienList()
          wx.showToast({
            title: '删除成功',
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },


  getPatienList() {
    var userID = wx.getStorageSync("user").userID;
    wx.request({
      url: getApp().globalData.myHttp + '/family/getFamilyPage',
      method: "GET",
      data: {
        userID: userID,
      },
      success: (result) => {
        if (result.data.success) {
          console.log(result)
          this.setData({
            patients: result.data.obj.records,
            num: result.data.obj.records.length
          })
        }
      }
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var isReport = options.isReport
    this.setData({
      isReport:isReport
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getPatienList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})